package com.happyclub.paul.dao;

import com.happyclub.pojo.TbPhotoLibrary;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

/**
 * @Auther: 魏泉琦
 * @Date: 2019/4/7 12:05
 * @Description: 相片表
 */
public interface PhotoLibraryRepostitory extends JpaRepository<TbPhotoLibrary,String> {

    /**
     *@Description: 通过相片编号查询相片信息
     *@Author: 魏泉琦
     *@date: 2019/4/7
     */
    @Query("select p from TbPhotoLibrary p where p.id=?1 ")
    TbPhotoLibrary queryPhotoLibraryByPhotoId(String photoId);


    /**
     *@Description: 增加相片
     *@Author: 魏泉琦
     *@date: 2019/4/8
     */
    @Modifying
    @Query(value = "INSERT into TB_PHOTO_LIBRARY(ID,PHOTO_URL,USER_ID,ALBUM_ID,OK,ACTIVITY_ID,CREATE_TIME) VALUES(?1,?2,?3,?4,?5,?6,SYSDATE)",nativeQuery = true)
    Integer createPhotoLibrary(String id,String photoUrl,String uerId,String albumId,Integer isOk,String activityId);
    
    /**
     *@Description: 查询所有相片库中相片状态的相片 -1未通过 0待审核 1已通过
     *@Author: 魏泉琦   queryTbPhotoLibrariesByOk
     *@date: 2019/4/11
     */
    List<TbPhotoLibrary> findTbPhotoLibrariesByOk(long isOk);

    /**
     *@Description: 保存并修改审核通过的相片
     *@Author: 魏泉琦
     *@date: 2019/4/11
     */
    @Modifying
    @Query("update TbPhotoLibrary pl set pl.ok=?1,pl.updateTime=SYSDATE where pl.id=?2")
    Integer updatePhotoByPhotoId(long isOk,String photoId);
    
    
    
    
    
    

    List<TbPhotoLibrary> findTbPhotoLibrariesByActivityId(String activityId);

    /**
     * @Author 高欢
     * @Description  通过相册编号查询差所有的相片
     * @Date 18:18 2019/4/9
     **/

    List<TbPhotoLibrary> findTbPhotoLibrariesByAlbumIdAndOk(String albumId,long ok);

    /**
     * @Author 高欢
     * @Description  更具活动ID删除相片
     * @Date 18:29 2019/4/9
     **/

    int deleteByActivityId(String activityId);
}
